$(function() {
    // $('p').on('click', function() {
    //     $(this).css('background', 'yellow')
    // })
    /******************静态事件区************* */
    let count = 7;
    let offset = 0;
    $('.panel-heading').hover(function() {
        $(this).toggleClass('bor')
    })
    $('.pagination li').click(function() {
        $('.pagination li').removeClass('active').removeAttr('aria-current')
        $(this).addClass('active').attr('aria-current', 'page')
    })
    $('#esc-user').click(function() {
        // alert(0)
        var msg = '您是否确定要退出当前操作！'
        if (confirm(msg) == true) {
            location.href = '/login'
            return true
        }
    });
    $('#collapseOne').click(function() {
        location.href = '/index'
    });
    $('#collapseTwo p:nth-child(1)').click(function() {
        location.href = '/baseproduct'
    });
    $('#collapseTwo p:nth-child(2)').click(function() {
        location.href = '/addproduction'
    });
    $('#collapseThree p').click(function() {
        location.href = '/financial'
    });
    $('#collapseFour p:nth-child(1)').click(function() {
        location.href = '/order'
    });
    $('#collapseFour p:nth-child(2)').click(function() {
        location.href = '/orderlist'
    });
    $('#collapseFive p:nth-child(1)').click(function() {
        location.href = '/stock'
    });
    /******************************* */


    /**************创建一个处理时间的类******************************* */
    class TimeUtils {
        formatDate(value) {
            let date = new Date(value);
            let year = date.getFullYear();
            let month = date.getMonth() + 1;
            month = month >= 10 ? month : '0' + month;
            let day = date.getDate();
            day = day >= 10 ? day : '0' + day;
            let hours = date.getHours();
            hours = hours >= 10 ? hours : '0' + hours;
            let minutes = date.getMinutes();
            minutes = minutes >= 10 ? minutes : '0' + minutes;
            let seconds = date.getSeconds();
            seconds = seconds >= 10 ? seconds : '0' + seconds;
            return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
        }
    }
    let timeUtils = new TimeUtils;
    /****************************************** */



    /*************************************************** */
    getUserInfo();

    function getUserInfo() {
        let token = sessionStorage.getItem('_tk')
        if (!token) {
            //token不存在返回登录页面
            location.href = '/login';
            return
        }

        $.ajax({
            type: 'POST',
            url: 'http://localhost:5001/userInfo',
            data: {
                token
            },
            success(result) {
                console.log(result)
                if (result.code == 303) {
                    if (confirm('您的身份信息已过期，请重新登录')) {
                        location.href = '/login'
                    }

                }
                if (result.code == 400) {
                    $('#user-img').attr('src', result.result[0].url)
                    $('#username').html(result.result[0].user)
                }

            }

        })
    }
    /*********************************** */

})